<template>
  <div class="tools">
    <el-button
      type="primary"
      icon="el-icon-plus"
      size="small"
      @click="$emit('add')"
      v-permission="addCode"
    >
      {{ $t('action.add') }}
    </el-button>
    <el-button
      type="primary"
      icon="el-icon-edit"
      size="small"
      :disabled="!singleSelected"
      @click="$emit('edit')"
      v-permission="editCode"
    >
      {{ $t('action.update') }}
    </el-button>
    <el-button
      type="primary"
      icon="el-icon-delete"
      size="small"
      :disabled="!selected"
      @click="$emit('remove')"
      v-permission="removeCode"
    >
      {{ $t('action.remove') }}
    </el-button>
    <el-button
      type="primary"
      icon="el-icon-upload2"
      size="small"
      @click="$emit('download')"
      v-permission="downloadCode"
    >
      {{ $t('action.export') }}
    </el-button>
  </div>
</template>

<script>
export default {
  name: 'Tools',
  props: {
    data: {
      type: Array,
      required: true
    },
    addCode: {
      type: String,
      default: ''
    },
    editCode: {
      type: String,
      default: ''
    },
    removeCode: {
      type: String,
      default: ''
    },
    downloadCode: {
      type: String,
      default: ''
    }
  },
  computed: {
    selected() {
      return this.data.length > 0
    },
    singleSelected() {
      return this.data.length === 1
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'styles/common.scss';
</style>
